package cn.kgc.jdktest.demo11;

import cn.afterturn.easypoi.excel.annotation.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * @Author:yaozhaobao
 * @Description:TODO
 * @version:1.0
 */
@NoArgsConstructor
@AllArgsConstructor
@Data
@Builder
@ExcelTarget("users")
public class UserExcel implements Serializable {
    @Excel(name = "编号", orderNum = "1", width = 10, needMerge = true)
//    @ExcelIgnore
    private Integer id;
    @Excel(name = "姓名", orderNum = "2", width = 20, needMerge = true)
    private String name;
    @Excel(name = "年龄", orderNum = "4", width = 10, needMerge = true)
    private Integer age;
    @Excel(name = "性别", orderNum = "5", width = 10, needMerge = true)
    private String gender;
    @Excel(name = "生日", orderNum = "3", width = 20.0, needMerge = true,
            exportFormat = "yyyy年MM月dd日", importFormat = "yyyy年MM月dd日")
    private Date birthday;
    //    @Excel(name = "爱好", orderNum = "6", width = 20.0)
    @ExcelIgnore
    private List<String> hobbys;
    @Excel(name = "爱好", orderNum = "6", width = 20.0, needMerge = true)
    private String hobbyStr;
    @ExcelEntity // 标识一对一的关系
    private Card card;
    @ExcelCollection(name = "订单信息", orderNum = "9")
//    @ExcelIgnore
    private List<Order> orders;
    // lombok自动生成setter/getter方法
    public String getHobbyStr() {
        StringBuilder sb = new StringBuilder();
        hobbys.forEach(e -> {
            sb.append(e).append(", ");
        });
        return sb.toString();
    }
}